package kstech.com.wifitest.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

import com.bumptech.glide.Glide;

import org.xutils.http.RequestParams;
import org.xutils.http.body.MultipartBody;
import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.Event;
import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;

import kstech.com.wifitest.R;
import kstech.com.wifitest.Test;
import kstech.com.wifitest.utils.Globals;
import kstech.com.wifitest.utils.JsonUtils;
import kstech.com.wifitest.utils.MyHttpUtils;

@ContentView(R.layout.activity_upload)
public class UploadActivity extends AppCompatActivity {
    @ViewInject(R.id.iv_local)
    ImageView imageView;
    @ViewInject(R.id.btn_upload_pic)
    Button btnUpload;
    private File file;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        x.view().inject(this);
        file = new File(Globals.LOCAL_PATH+"rrrr.jpeg");
        if(file.exists()){
            Glide.with(this).load(file).into(imageView);
        }
    }

    @Event(value={R.id.btn_upload_pic},type = View.OnClickListener.class)
    private void getEvent(View view){

        switch(view.getId()){
            case R.id.btn_upload_pic:
                new Thread(){
                    @Override
                    public void run() {
                        RequestParams params = new RequestParams("http://192.168.32.104:8080/SpringMVCTest/uploadpic");
                        params.setMultipart(true);
                        params.addBodyParameter("file",file);
                        String s = JsonUtils.toJson(new Test("fire","25"));
                        params.addBodyParameter("test",s);
                        new MyHttpUtils().xutilsUpload(params);
                    }
                }.start();
                break;
        }
    }
}
